import Static from './static.js'; // 导入参数


/**
 * 统一的音效管理器
 */
export default class Music extends Static {
	static instance = null; // 静态属性保存单例
	bgMusic = tt.createInnerAudioContext(); //背景音乐
	successMusic = tt.createInnerAudioContext(); //点击成功声音
	failCikMusic = tt.createInnerAudioContext(); //点击失败声音

	constructor() {
		if (Music.instance) return Music.instance;
		super(); // 必须调用父类构造函数
		Music.instance = this;
		this.isMusicOn = true; //背景音乐开启关闭
		this.bgMusic.loop = true; // 背景音乐循环播放
		// this.bgMusic.autoplay = true; // 背景音乐自动播放
		this.bgMusic.src = this.bgMusicSrc; // 背景音乐
		this.successMusic.src = this.successMusicSrc; //点击成功声音
		this.failCikMusic.src = this.failCikMusicSrc; //点击失败声音
		return Music.instance;
	}
	//背景音乐切换
	toggleMusic() {
		this.isMusicOn = !this.isMusicOn;
		if (this.isMusicOn) {
			this.playbgMusic()
		} else {
			this.pauseShoot()
		}
	}
	//背景音乐播放
	playbgMusic() {
		// this.bgMusic.currentTime = 0;
		this.bgMusic.play();
	}
	//背景音乐暂停
	pauseShoot() {
		this.bgMusic.pause();
	}
	//点击成功声音播放
	playSuccessMusic() {
		console.log("成功声音")
		this.successMusic.play();
	}
	//点击成功音乐暂停
	pauseSuccessMusic() {
		this.successMusic.pause();
	}
	//点击失败声音播放
	playFailCikMusic() {
		console.log("失败声音")
		this.failCikMusic.play();
	}
	//点击失败音乐暂停
	pauseFailCikMusic() {
		this.failCikMusic.pause();
	}
}